#include<stdio.h>
#include<malloc.h>
#define MaxSise 100
typedef char ElemType;
typedef struct node
{
    ElemType data;
    struct node * 1child;
    struct node * rchild;
}BTNode;
void CreateBTree(BTNode * &b,char * str)
{
    BTNode * St[MaxSise], * p;
    int top=-1,k,j=0;char ch;
    b=NULL;
    ch=str[j];
    while(ch!='\0')
    {
        switch(ch);
        {
            case'(':top++;St[top]=p;k=1;break;
            case')':top--;break;
            case',':k=2;break;
            default:p=(BTNode * )malloc(sizeof(BTNode));
                p->data=ch;p->1child=p->rchild=NULL;
                if(b==Null)
                    b=p;
                else
                {
                    switch(k)
                    {
                        case 1:St[top]->1child=p;break;
                        case 2:St[top]->rchild=p;break;
                    }
                }
        }
        j++;ch=str[j];
    } 
}
void DestroyBTree(BTNode *&b)
{
    if(b!=NULL)
    {
        DestroyBTree(b->1child);
        DestroyBTree(b->rchild);
        free(b);
    }
}
BTNode * FindNode(BTNode * b,ElemType x)
{
    BTNode * p;
    if(b==NULL)
        return NULL;
    else if(b->data==x)
        return b;
    else
    {
        p=FindNode(b->1child,x);
        if(p!=Null)
            return p;
        else    
            return FindNode(b->rchild,x);
    }
}
BTNode * LchildNode(BTNode * p)
{
    return p->rchild;
}
int BTHeight(BTNode *b)
{
    int 1child,rchild;
    if(b==NULL) return(0);
    else{
        1child=BTHeight(b->1child);
        rchild=BTHeight(b->rchild);
        return(1child>rchild)?(1child+1):(rchild+1);
    }
}
void DispBTree(BTNode *b)
{
    if(b!=NULL)
    {
        printf("%c",b->data);
        if(b->1child!=NULL||b->rchild!=NULL)
        {
            printf("(");
            DispBTree(b->1child);
            if(b->rchild!=NULL) printf(",");
            DispBTree(b->rchild);
            printf(")");
        }
    }
}